Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuring (opt-in) IMC async handler #8311

Merged

Conversation

pierDipi
Copy link
Member

@pierDipi pierDipi commented Nov 7, 2024

We switched to use the sync handler by default, however, it was
reported that in some cases, this is not wanted as it slows down
the source event senders since it needs to wait for all subscribers
to receive events.

While sync handler is the best default behavior since reduces lost events in
InMemoryChannel, we want to allow configuring this behavior, while
documenting the downsides (follow up to docs repo)

Proposed Changes

  • Allow configuring (opt-in) IMC async handler
  • Propagate annotations and labels from MTChannelBasedBroker to underlying channel

Pre-review Checklist

  • At least 80% unit test coverage
  • E2E tests for any new behavior
  • Docs PR for any user-facing impact
  • Spec PR for any new API feature
  • Conformance test for any change to the spec

Release Note

Allow configuring (opt-in) IMC async handler 

Docs

@knative-prow knative-prow bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. area/test-and-release Test infrastructure, tests or release labels Nov 7, 2024
@knative-prow knative-prow bot requested review from aslom and evankanderson November 7, 2024 08:25
@knative-prow knative-prow bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 7, 2024
Copy link

codecov bot commented Nov 7, 2024

Codecov Report

Attention: Patch coverage is 91.17647% with 3 lines in your changes missing coverage. Please review.

Project coverage is 64.62%. Comparing base (6b4ff7f) to head (b1e6f3d).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
pkg/reconciler/testing/v1/broker.go 50.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8311      +/-   ##
==========================================
+ Coverage   64.58%   64.62%   +0.03%     
==========================================
  Files         373      373              
  Lines       22619    22649      +30     
==========================================
+ Hits        14609    14636      +27     
- Misses       7244     7246       +2     
- Partials      766      767       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pierDipi pierDipi force-pushed the allow-configuring-imc-async-handler branch from 83f210b to 055fae7 Compare November 7, 2024 08:54
@@ -60,8 +60,11 @@ type Subscription struct {
// Config for a fanout.EventHandler.
type Config struct {
Subscriptions []Subscription `json:"subscriptions"`
// Deprecated: AsyncHandler controls whether the Subscriptions are called synchronous or asynchronously.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we release note that this is not deprecated anymore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only at the code level / library and we usually don't release note it since pretty much all users don't care

return &multichannelfanout.ChannelConfig{
Namespace: imc.Namespace,
Name: imc.Name,
HostName: imc.Status.Address.URL.Host,
Path: fmt.Sprintf("%s/%s", imc.Namespace, imc.Name),
FanoutConfig: fanout.Config{
AsyncHandler: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like a good idea to pass in the bool via configuration/annotation in case folks want to have it "async", and do not care about the impact.

@matzew
Copy link
Member

matzew commented Nov 7, 2024

While sync handler is the best default behavior since reduces lost events in
InMemoryChannel, we want to allow configuring this behavior, while
documenting the downsides (follow up to docs repo)

Seems like a good idea to document this. for the next upstream release.

/lgtm

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Nov 7, 2024
@matzew
Copy link
Member

matzew commented Nov 7, 2024

/test reconciler-tests

1 similar comment
@matzew
Copy link
Member

matzew commented Nov 8, 2024

/test reconciler-tests

@matzew
Copy link
Member

matzew commented Nov 8, 2024

=== FAIL: test/rekt TestBrokerPropagatesMetadata/Broker_PreferHeader_Check/Setup/install_broker (0.12s)
    broker.go:151: failed to create resource Broker in version "v1" cannot be handled as a Broker: json: cannot unmarshal bool into Go struct field ObjectMeta.annotations of type string - Resource:
        apiVersion: eventing.knative.dev/v1
        kind: Broker
        metadata:
          annotations:
            eventing.knative.dev/broker.class: MTChannelBasedBroker
            messaging.knative.dev/async-handler: false
          name: broker-bnjzunfv
          namespace: test-ckrgeeak
        spec: null
        
=== FAIL: test/rekt TestChannelAsyncHandler/AsyncHandlerUpdate/Requirement/update_channel_async_handler (0.40s)
    channel_impl.go:92: failed to update resource admission webhook "validation.inmemorychannel.eventing.knative.dev" denied the request: validation failed: Channel.Spec.Subscribers changed by user [email protected] which was not the system:serviceaccount:knative-eventing:eventing-controller service account: spec.subscribers
        {[]v1.SubscriberSpec}:
        	-: "[{Name:0xc0009a5ea0 UID:828704ea-0f50-48ab-bcd7-9b9cacc19796 Generation:1 SubscriberURI:http://sink-dwarkbpn.test-wcdvjxod.svc.cluster.local/ SubscriberCACerts: SubscriberAudience: ReplyURI: ReplyCACerts: ReplyAudience: Delivery: Auth:}]"
        	+: "[]"
         - Resource:
        apiVersion: messaging.knative.dev/v1
        kind: InMemoryChannel
        metadata:
          name: channel-nnnoytbn
          namespace: test-wcdvjxod
        spec: null

@matzew
Copy link
Member

matzew commented Nov 11, 2024

@pierDipi looks like some unmarshal error for the boolean value

}
for k, v := range metadata.GetAnnotations() {
if strings.HasPrefix(k, messagingv1.SchemeGroupVersion.Group) {
channelAnnotations[k] = v
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this always a string?

@knative-prow knative-prow bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 11, 2024
@@ -24,7 +24,7 @@ metadata:
{{ end }}
{{ if .annotations }}
{{ range $key, $value := .annotations }}
{{ $key }}: {{ $value }}
{{ $key }}: "{{ $value }}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for strings, using explicit ""... made the TestBrokerPropagatesMetadata work

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(works on my machine 😅 kinda fix)

@matzew
Copy link
Member

matzew commented Nov 11, 2024

=== FAIL: test/rekt TestChannelAsyncHandler/AsyncHandlerUpdate/Requirement/update_channel_async_handler (0.40s)
    channel_impl.go:92: failed to update resource admission webhook "validation.inmemorychannel.eventing.knative.dev" denied the request: validation failed: Channel.Spec.Subscribers changed by user [email protected] which was not the system:serviceaccount:knative-eventing:eventing-controller service account: spec.subscribers
        {[]v1.SubscriberSpec}:
        	-: "[{Name:0xc0009a5ea0 UID:828704ea-0f50-48ab-bcd7-9b9cacc19796 Generation:1 SubscriberURI:http://sink-dwarkbpn.test-wcdvjxod.svc.cluster.local/ SubscriberCACerts: SubscriberAudience: ReplyURI: ReplyCACerts: ReplyAudience: Delivery: Auth:}]"
        	+: "[]"
         - Resource:
        apiVersion: messaging.knative.dev/v1
        kind: InMemoryChannel
        metadata:
          name: channel-nnnoytbn
          namespace: test-wcdvjxod
        spec: null

is because of this: https://github.com/knative/eventing/blob/main/pkg/apis/messaging/v1/in_memory_channel_validation.go#L92

CC @pierDipi @Cali0707

@matzew
Copy link
Member

matzew commented Nov 12, 2024

/retest

@matzew matzew force-pushed the allow-configuring-imc-async-handler branch from 0feaf0b to 1389906 Compare November 12, 2024 07:38
@@ -17,6 +17,12 @@ kind: {{ .kind }}
metadata:
name: {{ .name }}
namespace: {{ .namespace }}
annotations:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when looking at the reconciler tests, I never saw the messaging.knative.dev/async-handler annotation, hence adding this

@@ -191,12 +193,28 @@ func AsyncHandlerUpdate(createSubscriberFn func(ref *duckv1.KReference, uri stri
f.Setup("channel is ready", channel_impl.IsReady(name))
f.Setup("subscription is ready", subscription.IsReady(sub))

f.Requirement("update channel async handler", channel_impl.Install(name, channel_impl.WithAnnotations(map[string]interface{}{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at the error again:

    channel_impl.go:92: failed to update resource admission webhook "validation.inmemorychannel.eventing.knative.dev" denied the request: validation failed: Channel.Spec.Subscribers changed by user [email protected] which was not the system:serviceaccount:knative-eventing:eventing-controller service account: spec.subscribers
        {[]v1.SubscriberSpec}:
        	-: "[{Name:0xc0009a5ea0 UID:828704ea-0f50-48ab-bcd7-9b9cacc19796 Generation:1 SubscriberURI:http://sink-dwarkbpn.test-wcdvjxod.svc.cluster.local/ SubscriberCACerts: SubscriberAudience: ReplyURI: ReplyCACerts: ReplyAudience: Delivery: Auth:}]"
        	+: "[]"

I saw that the subscribers are "replaced" w/ nothing (+:"[]"), which lead me to the fact that we here just re-install the channel_impl, based from its manifest yaml file, which lacks the actual subscribers

We switched to use the sync handler by default, however, it was
reported that in some cases, this is not wanted as it slows down
the source event senders since it needs to wait for all subscribers
to receive events.

While this is the best default behavior since reduces lost events in
InMemoryChannel, we want to allow configuring this behavior, while
documenting the downsides (follow up to docs repo)

Signed-off-by: Pierangelo Di Pilato <[email protected]>
Signed-off-by: Pierangelo Di Pilato <[email protected]>
pierDipi and others added 5 commits November 12, 2024 16:42
Signed-off-by: Pierangelo Di Pilato <[email protected]>
Signed-off-by: Pierangelo Di Pilato <[email protected]>
@matzew matzew force-pushed the allow-configuring-imc-async-handler branch from c180ebe to 859dfff Compare November 12, 2024 15:42
@matzew
Copy link
Member

matzew commented Nov 12, 2024

@pierDipi I've update the PR, for the async-handler update. Mainly changing the test. See comments above

@matzew
Copy link
Member

matzew commented Nov 12, 2024

/test unit-tests

…s. Otherwise we loose the channel's Spec.Subscribers

Signed-off-by: Matthias Wessendorf <[email protected]>
@matzew matzew force-pushed the allow-configuring-imc-async-handler branch from 859dfff to b1e6f3d Compare November 12, 2024 16:44
Copy link
Member Author

@pierDipi pierDipi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @matzew !

LGTM (I can't LGTM my own PR but the new changes look good)

@pierDipi pierDipi changed the title [WIP] Allow configuring (opt-in) IMC async handler Allow configuring (opt-in) IMC async handler Nov 18, 2024
@knative-prow knative-prow bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 18, 2024
Copy link
Member

@matzew matzew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Nov 18, 2024
Copy link

knative-prow bot commented Nov 18, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: matzew, pierDipi

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@matzew
Copy link
Member

matzew commented Nov 18, 2024 via email

@knative-prow knative-prow bot merged commit 8fed0be into knative:main Nov 18, 2024
35 of 36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/test-and-release Test infrastructure, tests or release lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants